﻿namespace HuaWei.EI
{
    using HuaWei.CommClass;
    using HuaWei.Common;
    using HuaWei.Windows.Forms;
    using System;
    using System.Collections;
    using System.Data;
    using System.Runtime.InteropServices;

    public class ExportBase : BaseIE
    {
        public DataSet dsSource;

        public void BuildBGLData()
        {
            string exeStr = string.Format("select * from {0} where updateStatus>0 and TYSB=1 and bdid='#bdid#'", "BGL");
            base.ExecuteDataSetEx(this.dsSource, exeStr, "BGL");
            exeStr = string.Format("select * from {0} where updateStatus>0 and pid in (select id from BGL where TYSB=1 and bdid='#bdid#') and bdid='#bdid#'", "BGLQD");
            base.ExecuteDataSetEx(this.dsSource, exeStr, "BGLQD");
            exeStr = string.Format("select * from {0} where updateStatus>0 and bdid='#bdid#'", "JLQD");
            base.ExecuteDataSetEx(this.dsSource, exeStr, "JLQD");
        }

        public void BuildJLSPData()
        {
            string exeStr = null;
            foreach (TableInfo info in base.tableInfoList)
            {
                exeStr = string.Format("select * from {0} where updateStatus>0 and bdid='#bdid#' and qcid='#qcid#'", info.TableName);
                base.ExecuteDataSetEx(this.dsSource, exeStr, info.TableName);
                if (info.Boolean)
                {
                    exeStr = string.Format("select * from {0} where updateStatus>0 and bdid='#bdid#' and qcid='#qcid#'", info.TableName + "2");
                    base.ExecuteDataSetEx(this.dsSource, exeStr, info.TableName + "2");
                }
            }
        }

        public void BuildXMData_old(ArrayList SQlList)
        {
            string exeStr = null;
            string tableName = "";
            exeStr = "select * from DelInfo where IsTrans=1";
            base.ExecuteDataSetEx(this.dsSource, exeStr, "DelInfo");
            exeStr = "update DelInfo set IsTrans=0 where IsTrans=1";
            SQlList.Add(exeStr);
            exeStr = string.Format("select * from {0} where updateStatus>0", "YHXX");
            base.ExecuteDataSetEx(this.dsSource, exeStr, "YHXX");
            exeStr = string.Format("update {0} set updateStatus=0 where updateStatus>0", "YHXX");
            SQlList.Add(exeStr);
            foreach (TableInfo info in base.list)
            {
                tableName = info.TableName;
                if (!tableName.Equals("XMJBXX"))
                {
                    exeStr = string.Format("select * from {0} where updateStatus>0", tableName);
                    base.ExecuteDataSetEx(this.dsSource, exeStr, info.TableName);
                    exeStr = string.Format("update {0} set updateStatus=0 where updateStatus>0", tableName);
                    SQlList.Add(exeStr);
                }
            }
        }

        public bool CheckExportData()
        {
            string exeStr = null;
            string str2 = null;
            foreach (TableInfo info in base.tableInfoList)
            {
                if (!info.LockField.Equals(""))
                {
                    if (info.TableName.Equals("QTJL_DYYFK"))
                    {
                        exeStr = "select #LockField# from #TableName# where (#LockField#=0 or #LockField# is null) and BQSQDYYFK > 0 and  bdid='#bdid#' and qcid='#qcid#'".Replace("#LockField#", info.LockField).Replace("#TableName#", info.TableName);
                    }
                    else
                    {
                        exeStr = "select #LockField# from #TableName# where (#LockField#=0 or #LockField# is null) and bdid='#bdid#' and qcid='#qcid#'".Replace("#LockField#", info.LockField).Replace("#TableName#", info.TableName);
                    }
                    if (base.ExecuteDataSetEx(exeStr, "checkLozk").Rows.Count > 0)
                    {
                        str2 = str2 + "\n\n* #CName#\n".Replace("#CName#", info.CName);
                    }
                }
            }
            if (str2 != null)
            {
                MsgBox.ShowMsg("以下单据的【同意上报】未沟选，请沟选后继续此操作！" + str2);
                return false;
            }
            return true;
        }

        public void IniExport(string qcid, string bdid, string bdName)
        {
            base.BDID = bdid;
            base.QCID = qcid;
            base.BDName = base.BDName;
            this.dsSource = new DataSet();
        }

        public void method6([Optional, DefaultParameterValue(false)] bool isAll)
        {
            string exeStr = null;
            if (isAll)
            {
                exeStr = string.Format("select * from {0} where updateStatus>0 and bdid='#bdid#'", "XMQC");
            }
            else
            {
                exeStr = string.Format("select * from {0} where updateStatus>0 and bdid='#bdid#' and qcid={1}", "XMQC", base.QCID);
            }
            base.ExecuteDataSetEx(this.dsSource, exeStr, "XMQC");
        }

        public void method7(JGLX jglx)
        {
            string exeStr = "";
            switch (jglx)
            {
                case JGLX.YZ:
                    exeStr = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQZFZS", base.BDID, base.QCID);
                    base.ExecuteDataSetEx(this.dsSource, exeStr, "REP_ZQZFZS");
                    exeStr = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQJKZF1", base.BDID, base.QCID);
                    base.ExecuteDataSetEx(this.dsSource, exeStr, "REP_ZQJKZF1");
                    exeStr = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQJKZF2", base.BDID, base.QCID);
                    base.ExecuteDataSetEx(this.dsSource, exeStr, "REP_ZQJKZF2");
                    exeStr = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_GCBG", base.BDID, base.QCID);
                    base.ExecuteDataSetEx(this.dsSource, exeStr, "REP_GCBG");
                    break;

                case JGLX.CBR:
                    exeStr = string.Format("update qdjl_mx set bqjls1=bqjls where bdid='{0}' and qcid={1}", base.BDID, base.QCID);
                    base.ida.ExecuteNonQuery(exeStr, CommandType.Text);

                    exeStr = string.Format("update BGQDJL_MX set bqjls1=bqjls where bdid='{0}' and qcid={1}", base.BDID, base.QCID);
                    base.ida.ExecuteNonQuery(exeStr, CommandType.Text);

                    base.ExecuteDataSetEx(this.dsSource, "select * from CTFL where bdid='" + base.BDID + "'", "CTFL");

                    base.ExecuteDataSetEx(this.dsSource, "select * from gclct where bdid='" + base.BDID + "'", "gclct");
                    break;
            }
            exeStr = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "XMQC", base.BDID, base.QCID);
            base.ExecuteDataSetEx(this.dsSource, exeStr, "XMQC");
            foreach (TableInfo info in base.tableInfoList)
            {
                exeStr = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", info.TableName, base.BDID, base.QCID);
                base.ExecuteDataSetEx(this.dsSource, exeStr, info.TableName);
            }
        }

        public void method8(ArrayList SQlList)
        {
            string exeStr = null;
            string tableName = "";
            exeStr = string.Format("select * from {0}", "YHXX");
            base.ExecuteDataSetEx(this.dsSource, exeStr, "YHXX");
            foreach (TableInfo info in base.list)
            {
                tableName = info.TableName;
                if (!tableName.Equals("XMJBXX"))
                {
                    exeStr = string.Format("select * from {0}", tableName);
                    base.ExecuteDataSetEx(this.dsSource, exeStr, info.TableName);
                }
            }
        }

        public void method9(string xmid)
        {
        }
    }
}

